
ac.buff("浮空"){

    displace = true,
    level = 1,
    pulse = 0.03,
    
    height = 512,       --- 飞行高度
    speed = 3000,       --- 飞行速度

    on_add = function(self)
        local unit = self.owner 
        self.now_height = unit:get_height()
        self.max_height = self.now_height + self.height
        self.has_upward = self.now_height <= self.max_height
        self.has_resume = true
        self.has_launch = true 
        unit:notify("单位-打断位移", unit)
        unit:add_restriction "位移"
        unit:add_restriction "幽灵"
        unit:add_restriction "定身"
        self.trigger = unit:on "单位-打断位移" (function (_, _, flag)
            self.has_resume = (flag == true) 
            self:remove()
        end)
        self:notify("on_launch")
    end,

    on_pulse = function(self)
        if self.has_upward then 
            self.now_height = math.min(self.now_height + self.speed * self.pulse, self.max_height)
        else 
            self.now_height = math.max(self.now_height - self.speed * self.pulse, self.max_height)
        end
        self.owner:set_height(self.now_height)
        if self.now_height == self.max_height then 
            self:notify("on_finish")
            self:remove()
        end 
    end,

    on_remove = function(self)
        local unit = self.owner 
        unit:remove_restriction "位移"
        unit:remove_restriction "幽灵"
        unit:remove_restriction "定身"
        if self.trigger then 
            self.trigger:remove()
        end 
        if self.has_resume then 
            unit:set_height( unit:get_default_height() )
        end 
        if self.has_launch then 
            self:notify("on_stop")
        end 
    end,

    on_cover = function(self, new)
        self.has_resume = false
        return true
    end,
}